---
title: Query language
toc_max_heading_level: 4
tags: [query, lang, mql]
---

import VersionLabel from '@site/src/components/Docs/VersionLabel';

<VersionLabel version="1.3.0" header />

moon supports an integrated query language, known as MQL, that can be used to filter and select
projects from the project graph, using an SQL-like syntax. MQL is primarily used by
[`moon run`](../commands/run) with the `--query` option.

## Syntax

### Comparisons

A comparison (also known as an assignment) is an expression that defines a piece of criteria, and is
a building block of a query. This criteria maps a [field](#fields) to a value, with an explicit
comparison operator.

#### Equals, Not equals

The equals (`=`) and not equals (`!=`) comparison operators can be used for _exact_ value matching.

```
projectType=library && language!=javascript
```

You can also define a list of values using square bracket syntax, that will match against one of the
values.

```
language=[javascript, typescript]
```

#### Like, Not like

The like (`~`) and not like (`!~`) comparison operators can be used for _wildcard_ value matching,
using [glob syntax](./file-pattern#globs).

```
projectSource~packages/* && tag!~*-app
```

> Like comparisons can only be used on non-enum fields.

### Conditions

The `&&` and `||` logical operators can be used to combine multiple comparisons into a condition.
The `&&` operator is used to combine comparisons into a logical AND, and the `||` operator is used
for logical OR.

```
taskToolchain=system || taskToolchain=node
```

For readability concerns, you can also use `AND` or `OR`.

```
taskToolchain=system OR taskToolchain=node
```

> Mixing both operators in the same condition is not supported.

### Grouping

For advanced queries and complex conditions, you can group comparisons using parentheses to create
logical groupings. Groups can also be nested within other groups.

```
language=javascript && (taskType=test || taskType=build)
```

## Fields

The following fields can be used as criteria, and are related to [task tokens](./token#variables).

### `language`

Programming language the project is written in, as defined in
[`moon.yml`](../config/project#language).

```
language=rust
```

### `project`

Name OR alias of the project.

```
project=server
```

### `projectAlias`

Alias of the project. For example, the `package.json` name.

```
projectAlias~@scope/*
```

### `projectLayer`<VersionLabel version="1.39.0" />

The project layer, as defined in [`moon.yml`](../config/project#layer).

```
projectLayer=application
```

### `projectName`

Name of the project, as defined in [`.moon/workspace.yml`](../config/workspace), or `id` in
[`moon.yml`](../config/project#id).

```
project=server
```

### `projectSource`

Relative file path from the workspace root to the project root, as defined in
[`.moon/workspace.yml`](../config/workspace).

```
projectSource~packages/*
```

### `projectStack`<VersionLabel version="1.22.0" />

The project stack, as defined in [`moon.yml`](../config/project#stack).

```
projectStack=frontend
```

### `projectType`

> This field is deprecated, use `projectLayer` instead.

The type of project, as defined in [`moon.yml`](../config/project#layer).

```
projectType=application
```

### `tag`

A tag within the project, as defined in [`moon.yml`](../config/project#tags).

```
tag~react-*
```

### `task`

ID/name of a task within the project.

```
task=[build,test]
```

### `taskToolchain`<VersionLabel version="1.31.0" />

The toolchain a task will run against, as defined in [`moon.yml`](../config/project).

```
taskToolchain=node
```

### `taskType`

The [type of task](./task#types), based on its configured settings.

```
taskType=build
```
